import fs from 'fs'
import { PNG } from 'pngjs'
import pixelmatch from 'pixelmatch'

const img1 = PNG.sync.read(fs.readFileSync('./pics/斯巴鲁-常州斯巴鲁_1.png'))
const img2 = PNG.sync.read(fs.readFileSync('./pics/斯巴鲁-常州斯巴鲁_2.png'))
const { width, height } = img1
const diff = new PNG({ width, height })

pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold: 0.1 })

fs.writeFileSync('diff.png', PNG.sync.write(diff))
